﻿<%@ page pageEncoding="UTF-8" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head> 
	<title>CrecheBook</title>
	<!-- meta -->
	<meta name="description" content="">
	<meta name="author" content="M. Steve">
	<link rel="shortcut icon" href="favicon.ico">
	<meta charset="UTF-8">
	
	<!-- CSS-->
	<link rel="stylesheet" href="medias/css/core.css" type="text/css" media="screen">
	
	<!-- JS -->
	<script src="medias/javaScript/inputs.js"></script>
	
	<!-- Google MAPS -->
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
	
	<!-- JQuery -->
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
	<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
	
</head> 
<body > 

	<%@ page import = "Creche.Bd.BD" %>
	<%@page import = "Creche.Main.Creche"%>
	<%@page import = "Creche.Donnees.Donnee"%>
	<%@page import = "Creche.Donnees.Actualite"%>
	<%@page import = "java.util.ArrayList" %>	
	<%@page import = "Creche.Admin.Administrateur" %>
	<%@page import = "java.sql.Date" %>
	<%@page import = "java.text.SimpleDateFormat" %>

	<div data-role="page">
	
	
		<div data-role="header">
		
			
			
			<div id="banniere">
				<br>
				<br>
				<h1 >CrecheBook</h1>
			</div>
			
			<div id="searchBox">
			
			<%
				String nom = "";
				String ville = "";
				if (request.getParameter("nom")!= null || request.getParameter("ville")!= null)
				{
					nom = request.getParameter("nom");
					ville = request.getParameter("ville");
					
					nom.toLowerCase();
					
				}else response.sendRedirect("search.jsp"); 
			%>
			
			
				<div class="ui-bar ui-bar-c">	
						
					<%	
						String url = "creche.jsp?nom="+nom+"&ville="+ville;
						out.print("<a href=\""+url+"\" data-role='button' data-theme='c' data-corners='true' data-icon='arrow-l' data-inline='true' data-ajax='false'>Retour</a>");
						String nomFormat = nom.toLowerCase(); 
						out.print("<h1>" +ville + " | " + nomFormat +"</h1>");
						
					%>   


				</div>
	

			 </div>
				
				
	 
		</div><!-- /header -->
	
		<div data-role="content">

			
			
			
			
			<% 
	
				if (request.getParameter("nom")!= null || request.getParameter("ville")!= null)
				{
				
					
					out.print("<div class='ui-bar ui-bar-c' ><h2 > Informations générales </h2></div><div class='ui-body ui-body-d'>");
					
					

					/*String nom = request.getParameter("nomCreche");*/
					// On va afficher toutes les informations des cr?ches
					// dans des zeones de textes pour qu'elles puissent 
					// ?tre modifier ? l'aide d'une servlet
					BD myBase = new BD();
					Creche courrante = myBase.getCreche(nom,ville);
					session.setAttribute("creche", courrante);
					//administrateur, voir si il est connecter
					Administrateur admin = (Administrateur)request.getSession().getAttribute("session");
					// au cas o? la cr?che n'existe pas
					if (courrante != null){
						// on fr?cup?re les donn?es de la cr?che
						ArrayList<Donnee> listeD = courrante.getSeulementDonnees();
						ArrayList<Actualite> listeA = courrante.getActu();
						// on met la cr?che dans une variable de session pour la modifier ult?rieurement 
						session.setAttribute("creche", courrante);
						out.print("<form name ='donnee' method = POST action = validation>");
						out.println("<input type = 'hidden' name ='nom' value = '" + nom+"'><br>");
						out.println("<input type = 'hidden' name = 'ville' value = '" + ville+"'>");

						
						for (int i= 0; i < listeD.size(); i++) {
							out.println(listeD.get(i).getLabel()+" ");
							out.println("<input type = text name ="+listeD.get(i).getLabel()+" value = '"+listeD.get(i).getVal()+"'><BR>");
						}
						
						if(listeD.size() == 0)
						{
							out.println("<p style='color:#CCCCCC;font-size:10px;'>Il n'y a aucune nouvelle information.</p>");
							out.println("<input type ='submit' value = 'Sauvegarder' disabled data-icon='refresh'></form>");
							
						} else out.println("<input type ='submit' value = 'Sauvegarder'  data-icon='refresh'></form>");
						
						
						out.println("</div><br><div class='ui-bar ui-bar-c'><h2> Ajouter une information </h2></div><div class='ui-body ui-body-d'>");
						out.print("<form action = ajout method = POST data-ajax = \"false\" >");
						out.println("<input type = 'hidden' name ='nom' value = '" + nom+"'><br>");
						out.println("<input type = 'hidden' name = 'ville' value = '" + ville+"'>");
						
						%>
							
								<div class="ui-grid-a">
									<div class="ui-block-a">Titre:<input type = text name = label></div>
									<div class="ui-block-b">Description:<input type = text name = valeur ></div>
								</div>
								<p style='text-align:right'><input type = submit value = Ajouter data-icon='plus' ></p>
								</form>
							</div>
						<%
						
						if (admin != null) {
						
						out.print("<h2 > Evènements </h2>");
						

						for(int i = 0; i < listeA.size(); i++) 
						{
							SimpleDateFormat formatDateJour = new SimpleDateFormat("dd/MM/yyyy");
							String dateFormatee = formatDateJour.format(listeA.get(i).getDate()); 
							
							out.println("<div data-role='collapsible' data-theme='b' data-content-theme='d' data-collapsed='false'><h4>" + 
								listeA.get(i).getLabel()+ "&nbsp; -&nbsp;"+dateFormatee+"</h4><form name = 'actu' action = 'validation' method = POST><br><br>" +listeA.get(i).getVal()+
								"<br><br><input type = 'hidden' name = 'nomActu' value ='" + listeA.get(i).getLabel() +
								"'><p style='text-align:right'><input type = 'submit' name = 'Supprimer' value = 'Supprimer' class='button1'></form></p></div>");

						}
						}

					}
				}
				else response.sendRedirect("search.jsp"); 
				

				
				
			%>

			
		</div><!-- /content -->
	
		<div data-role="footer">
			
			<h4 style="margin:30px;">
				<strong> CrecheBook 2013</strong> <br>
				<a href="legal.jsp" data-ajax="false">Mentions&nbsp;l&eacute;gales</a>&nbsp;|&nbsp;
				<a href="connexion" data-ajax="false">Administateur</a>
			 </h4>
				
		</div><!-- /footer -->
	</div><!-- /page -->

</body>
</html>